LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-20-2008, 01:29 AM   #1
mundy
LQ Newbie
 
Registered: Oct 2005
Distribution: Debian Etch
Posts: 8

Rep: Reputation: 0
Command Line Video Text Overlay


Presently I have a working system of scripts that uses MEncoder to cut and join video files together with a handful of other options etc. It's all automated and working and that's just dandy.

What I'm looking for now is a way to place text over the video using the scripts. This would be done in a similar way to subtitles, except the subtitles would be embedded in the video (so each frame actually includes the text as part of the actual frame itself).

Is there a software package/library that does this via the command line? or in some other way that can be easily managed with scripts?

Does this functionality already exist in MEncoder?

I'll give you a few examples of what I'm after.

Basically I have a script that reads in a handful of timecodes and a video file from a database, invokes mencoder to cut the specified clips from the source videos, then uses mencoder to join them all into a single file.

What I want to be able to do is:
a) Provide a timestamp on the video that would obviously update each second (this could all be calculated by the script)

b) Take some extra text from the database, along with the clip timecodes and overlay it onto the specific clip

None of this seems like it would be particularly hard to do, software wise, but i've been searching and searching for a software library that can do it with little luck.

Anyone have any ideas?

I'd be willing to PayPal somebody like $50 AUD if they can point me in the right direction o_0
 
Old 06-20-2008, 07:18 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
There are a few ways you could go about doing this. For example, use ImageMagick on each frame separately. But I think you already hit on the easiest way—using subtitles.

Certain formats of subtitle files are easy to generate programatically (e.g., srt). Generally, if the subtitle and movie file are in the same directory (with the same basename), mplayer will automatically use the subtitle file and overlay the text (with some adjustable font and style parameters).

When using mencoder, on the other hand, you can use this behavior to “hardcode” the subtitles onto the resulting movie file using the “-sub” flag (although I think there were certain bugs with this usage on older builds of mencoder). Here is an example usage.

So I think the steps are to have a script or program (I would use Perl) to generate a text-based subtitle file with the text you want (using the format shown in the linked-to wiki page). Then, use mencoder to hardcode the subtitle file onto a single resultant video file.

Edit:
P.S. If you were serious about the PayPal, send me a personal message through email, and we could discuss that further.

Last edited by osor; 06-20-2008 at 08:10 PM. Reason: postscript
 
Old 06-21-2008, 05:23 AM   #3
mundy
LQ Newbie
 
Registered: Oct 2005
Distribution: Debian Etch
Posts: 8

Original Poster
Rep: Reputation: 0
Using the subtitle method, would I be able to change things like position on screen, background colours etc? I'm assuming using the subtitle method I'd be limited to just text too?
 
Old 06-21-2008, 11:51 AM   #4
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by mundy View Post
Using the subtitle method, would I be able to change things like position on screen, background colours etc? I'm assuming using the subtitle method I'd be limited to just text too?
With mencoder itself, I believe you can change things like font, color, style, etc. combined with somewhat crude vertical positioning (-subpos <0-100>).

But of course mencoder is not the only software capable of “flattening” a subtitle onto a video. If you want something more robust, take a look at spumux from the dvdauthor package. I am sure there is other software out there which has similar features.
 
Old 06-21-2008, 04:30 PM   #5
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
I forgot to mention that instead of subtitles you can use mencoder’s cousin—ffmpeg, which has all sorts of plugins (called vhooks).

If you have the correct build of ffmpeg, there are two vhooks you may be interested in: drawtext and imlib2 (for plain and fancy text respectively). You can also use the ppm and watermark vhooks for overlaying images.

Here is the documentation for using the hooks.

Last edited by osor; 06-21-2008 at 04:33 PM.
 
Old 06-22-2008, 08:57 PM   #6
mundy
LQ Newbie
 
Registered: Oct 2005
Distribution: Debian Etch
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by osor View Post
If you have the correct build of ffmpeg, there are two vhooks you may be interested in: drawtext and imlib2 (for plain and fancy text respectively). You can also use the ppm and watermark vhooks for overlaying images.
That looks like it's exactly what I'm after. I have ffmpeg installed on my system (Debian etch) but I'm unsure as to how to install these vhooks, or even to find out if they exist.

I tried calling ffmpeg with the -vhook option to see what happened:

Code:
$ ffmpeg -vhook 'vhook/imlib2.so'
<<ffmpeg version and usage output>>
vhook/imlib2.so: cannot open shared object file: No such file or directory
Failed to add video hook function: vhook/imlib2.so
I'm guessing I don't have the vhooks installed?

How do I install them so I can start using them? o_0
 
Old 06-22-2008, 09:22 PM   #7
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by mundy View Post
That looks like it's exactly what I'm after.
I suppose you mean for “Part B” from your OP, since the vhooks are more for an overlay than for dynamic text (the timecode requirement of “Part A” could be met solely by use of hardcoded subtitles).
Quote:
Originally Posted by mundy View Post
I have ffmpeg installed on my system (Debian etch) but I'm unsure as to how to install these vhooks, or even to find out if they exist.

I tried calling ffmpeg with the -vhook option to see what happened:

Code:
$ ffmpeg -vhook 'vhook/imlib2.so'
<<ffmpeg version and usage output>>
vhook/imlib2.so: cannot open shared object file: No such file or directory
Failed to add video hook function: vhook/imlib2.so
I'm guessing I don't have the vhooks installed?

How do I install them so I can start using them? o_0
I am not quite sure what to say since I don’t use Debian (on my system, the the file is /usr/lib/vhook/imlib2.so). You can try “locate imlib2.so” to see if that gives up any files (if so, you can specify the full path at the command-line).

Perhaps you could try the ffmpeg package provided by debian-multimedia (whose manifest shows the so-files in the correct location). If none of this works, you could build from scratch.
 
Old 06-22-2008, 10:20 PM   #8
mundy
LQ Newbie
 
Registered: Oct 2005
Distribution: Debian Etch
Posts: 8

Original Poster
Rep: Reputation: 0
locate imlib2.so returned /usr/lib/vhook/imlib2.so which obviously means it's on my system. I'm currently fiddling with it now, I'll let you know how I go.

As for the subtitle embedding with mencoder, I've put together a .srt file and used the -sub option in mencoder, but the resulting file returns with no subtitles at all. Heres the options i used:

Code:
$ mencoder "input.avi" -ovc copy -oac copy -sub subs.srt -o output.avi
and here's the first few lines of my srt file:

Code:
1
00:00:00,000 --> 00:00:00,999
Q1 00:00

2
00:00:01,000 --> 00:00:01,999
Q1 00:01

3
00:00:02,000 --> 00:00:02,999
Q1 00:02

4
00:00:03,000 --> 00:00:03,999
Q1 00:03

5
00:00:04,000 --> 00:00:04,999
Q1 00:04
 
Old 06-22-2008, 10:42 PM   #9
mundy
LQ Newbie
 
Registered: Oct 2005
Distribution: Debian Etch
Posts: 8

Original Poster
Rep: Reputation: 0
I'm also having a problem with ffmpeg and the imlib2.so vhook:

(using an example from the documentation page)

Code:
$ ffmpeg -i "input.avi" -vhook '/usr/lib/vhook/imlib2.so -c white -F VeraBd.ttf/12 -x 0 -y 0 -t %A-%D-%T' output.avi

FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2007 Fabrice Bellard, et al.
  configuration: --prefix=/usr --libdir=${prefix}/lib --shlibdir=${prefix}/lib --incdir=${prefix}/include/ffmpeg --enable-shared --enable-libmp3lame --enable-gpl --enable-libfaad --mandir=${prefix}/share/man --enable-libvorbis --enable-pthreads --enable-libfaac --enable-xvid --enable-libdts --enable-amr_nb --enable-amr_wb --enable-pp --enable-libogg --enable-libgsm --enable-x264 --enable-liba52 --enable-libtheora --extra-cflags=-Wall -g -fPIC -DPIC --cc=ccache cc --enable-swscaler
  libavutil version: 49.4.0
  libavcodec version: 51.40.2
  libavformat version: 51.11.0
  built on Mar 29 2007 11:08:52, gcc: 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
Input #0, avi, from 'input.avi':
  Duration: 01:01:24.4, start: 0.000000, bitrate: 1767 kb/s
  Stream #0.0: Video: mpeg4, yuv420p, 640x480, 25.00 fps(r)
  Stream #0.1: Audio: adpcm_ima_wav, 32000 Hz, stereo, 257 kb/s

/usr/lib/vhook/imlib2.so: undefined symbol: exit_is_forbidden
Failed to add video hook function: /usr/lib/vhook/imlib2.so -c white -F VeraBd.ttf/12 -x 0 -y 0 -t %A-%D-%T
I've tried playing around with the options handed to imlib2.so, thinking perhaps the documentation was out of date but it seems no matter what I do the same error occurs.

I searched google with the error message but so far have only been able to find some gentoo specific help.

Any ideas?
 
Old 06-23-2008, 02:52 PM   #10
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by mundy View Post
As for the subtitle embedding with mencoder, I've put together a .srt file and used the -sub option in mencoder, but the resulting file returns with no subtitles at all. Heres the options i used:

Code:
$ mencoder "input.avi" -ovc copy -oac copy -sub subs.srt -o output.avi
There is one of a couple problems here:
  1. Subtitles will not be hardcoded unless you are re-encoding the video (so you can’t expect “-ovc copy” to work). My advice is to keep all video parameters the same (you can use midentify in a script to get those parameters), and use “-oac copy” for the audio.
  2. Even when using a different ovc, I alluded to previously encountered bugs in older builds of mplayer in which subtitle hardcoding didn’t work (see this thread). So if the problem persists when you follow 1., I suggest getting a newer build of mplayer/mencoder (perhaps from the repository linked above).
 
Old 06-23-2008, 02:57 PM   #11
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by mundy View Post
I'm also having a problem with ffmpeg and the imlib2.so vhook:
<SNIP>
I searched google with the error message but so far have only been able to find some gentoo specific help.
When I searched google with that error message, I came up with this hit.

P.S.,
You might also try the debian-multimedia repository I linked above.

Last edited by osor; 06-23-2008 at 02:58 PM. Reason: postscript
 
Old 06-23-2008, 08:57 PM   #12
mundy
LQ Newbie
 
Registered: Oct 2005
Distribution: Debian Etch
Posts: 8

Original Poster
Rep: Reputation: 0
Both MPlayer/MEncoder and FFMPEG were installed from the debian-multimedia repository in the first place. I'll do an upgrade and see if that helps the vhook problems.

I'll give the subtitles another go with your advice too and let you know how I go.

Thanks =)
 
Old 06-24-2008, 01:08 AM   #13
mundy
LQ Newbie
 
Registered: Oct 2005
Distribution: Debian Etch
Posts: 8

Original Poster
Rep: Reputation: 0
Still unable to get mencoder to embed the subtitles. I'm re-encoding the video and the path the the subs.srt file is fine but still not having any luck.

Code:
$ mencoder "input.avi" -oac copy -ovc xvid -xvidencopts bitrate=1500 -sub subs.srt -o output.avi
I've updated it to the latest version available, but still no luck =/

As far as the ffmpeg vhook goes, I got it to work. As the vhook only allows static text overlays, I had to get my script to generate a separate command for each second which would create a 1 second long clip for each clip.

This works... It's just not every practical to break the clips down further into 1 second clips and then join them again.

Anyone have any other ideas?
 
Old 06-24-2008, 08:48 PM   #14
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by mundy View Post
Still unable to get mencoder to embed the subtitles. I'm re-encoding the video and the path the the subs.srt file is fine but still not having any luck.

Code:
$ mencoder "input.avi" -oac copy -ovc xvid -xvidencopts bitrate=1500 -sub subs.srt -o output.avi
I've updated it to the latest version available, but still no luck =/
That would be version 1.0rc2? The above line works for me verbatim (on this test video, and the test srt file you provided) both on a Gentoo machine and an Ubuntu 8.04. Perhaps you should try from a testing or unstable repo. Or even compile the latest source.
Quote:
Originally Posted by mundy View Post
As far as the ffmpeg vhook goes, I got it to work.
Well, this is good news. I agree that splitting up the file into one-second chunks is a horrible way to go.

If you still can’t get mencoder to work for you, you could always use something else for hardsubbing. Does spumux not work since you’re dealing with xvid? Another option is vlc, which can probably do hardcoding of subtitles, but I am not sure of its script-friendliness. Also, there may be a way to interface with a library like gstreamer, and write the overlay code as part of a program/script.
 
Old 06-24-2008, 08:49 PM   #15
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by mundy View Post
Both MPlayer/MEncoder and FFMPEG were installed from the debian-multimedia repository in the first place.
Then maybe try the normal debian repository (unless you’ve already tried that).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Enhanced command line text editor netsoft2005 Linux - Software 2 07-14-2005 07:42 AM
Copy text from command line Duukkis Linux - General 8 08-25-2003 01:29 PM
VI text editor in command line InSane103 Linux - Software 4 07-09-2003 09:04 PM
Command line Text Terri Linux - General 8 04-05-2002 03:10 PM
command line text formating anyone? DavidPhillips Linux - General 2 11-25-2001 06:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration